package com.stylefeng.guns.modular.system.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.modular.system.model.Jarset;
import com.stylefeng.guns.modular.system.service.IJarsetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * jar包控量控制器
 *
 * @author fengshuonan
 * @Date 2018-10-22 16:50:12
 */
@Controller
@RequestMapping("/jarset")
public class JarsetController extends BaseController {

    private String PREFIX = "/system/jarset/";

    @Autowired
    private IJarsetService jarsetService;

    /**
     * 跳转到jar包控量首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "jarset.html";
    }

    /**
     * 跳转到添加jar包控量
     */
    @RequestMapping("/jarset_add")
    public String jarsetAdd() {
        return PREFIX + "jarset_add.html";
    }

    /**
     * 跳转到修改jar包控量
     */
    @RequestMapping("/jarset_update/{jarsetId}")
    public String jarsetUpdate(@PathVariable Integer jarsetId, Model model) {
        Jarset jarset = jarsetService.selectById(jarsetId);
        model.addAttribute("item",jarset);
        LogObjectHolder.me().set(jarset);
        return PREFIX + "jarset_edit.html";
    }

    /**
     * 获取jar包控量列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return jarsetService.selectList(null);
    }

    /**
     * 新增jar包控量
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Jarset jarset) {
        jarsetService.insert(jarset);
        return SUCCESS_TIP;
    }

    /**
     * 删除jar包控量
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer jarsetId) {
        jarsetService.deleteById(jarsetId);
        return SUCCESS_TIP;
    }

    /**
     * 修改jar包控量
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Jarset jarset) {
        jarsetService.updateById(jarset);
        return SUCCESS_TIP;
    }

    /**
     * jar包控量详情
     */
    @RequestMapping(value = "/detail/{jarsetId}")
    @ResponseBody
    public Object detail(@PathVariable("jarsetId") Integer jarsetId) {
        return jarsetService.selectById(jarsetId);
    }
}
